import request from './request'
//获取已选中的课程
export function getCourseSchedule() {
  return request({
    method: 'get',
    url: `/course/getCourseList`
  })
}
//搜索所有课程
export function searchCourse({
  page,
  pageSize,
  type,
  name,
  index,
  teacher
}: {
  page: number
  pageSize: number
  type: number
  name: string
  index: string
  teacher: string
}) {
  return request({
    method: 'get',
    url: 'course/searchCourse',
    params: {
      page: page,
      pageSize: pageSize,
      type: type,
      ...(name !== '' ? { courseName: name } : {}),
      ...(index !== '' ? { index: index } : {}),
      ...(teacher !== '' ? { teacherName: teacher } : {})
    }
  })
}
//选课
export function selectCourse(id: number) {
  return request({
    method: 'post',
    url: 'course/selectCourse',
    params: {
      courseId: id
    }
  })
}
//退课
export function dropCourse(id: number) {
  return request({
    method: 'patch',
    url: 'course/dropCourse',
    params: {
      courseId: id
    }
  })
}
//查询课程成绩
export function getScore(id?: number) {
  return request({
    method: 'get',
    url: 'course/getScore',
    params: {
      courseId: id
    }
  })
}
//添加课程备注
export function addComment(id: number, comment: string) {
  return request({
    method: 'patch',
    url: 'course/updateComment',
    params: {
      id: id,
      comment: comment
    }
  })
}
//获取学生的选课成绩
export function getAllScore(id: number) {
  return request({
    method: 'get',
    url: 'course/getAllScore',
    params: {
      id: id
    }
  })
}
//更新学生课程成绩
export function updateScore(userId: number, courseId: number, regular: number, finalScore: number) {
  return request({
    method: 'patch',
    url: 'course/updateScore',
    params: {
      userId: userId,
      courseId: courseId,
      regular: regular,
      finalScore: finalScore
    }
  })
}
//更新课程
export function updateCourse(courseData: any) {
  return request({
    method: 'patch',
    url: 'course/updateCourse',
    data: JSON.stringify(courseData),
    headers: {
      'Content-Type': 'application/json'
    }
  })
}
//删除课程
export function deleteCourse(id: number) {
  return request({
    method: 'delete',
    url: 'course/deleteCourse',
    params: {
      courseId: id
    }
  })
}
//添加课程
export function addCourse(courseData: any) {
  return request({
    method: 'post',
    url: 'course/addCourse',
    data: JSON.stringify(courseData),
    headers: {
      'Content-Type': 'application/json'
    }
  })
}
//更新上课教师
export function updateTeacher(courseId: number, teacherIdList: string) {
  return request({
    method: 'patch',
    url: 'course/updateCourseTeacher',
    params: {
      courseId: courseId,
      teacherList: teacherIdList
    }
  })
}
